package leetcode_day._2022._202202._2128;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/2/23 19:58
 * 仅仅反转字母
 * 算法：双指针
 */
public class _23_917 {

    public String reverseOnlyLetters(String s) {
        int l = 0, r = s.length() - 1;
        char[] arr = s.toCharArray();
        while (l < r) {
            while (l < r && !Character.isLetter(arr[l])) ++l;
            while (l < r && !Character.isLetter(arr[r])) --r;
            if (l < r) {
                char tmp = arr[l];
                arr[l++] = arr[r];
                arr[r--] = tmp;
            }
        }
        return new String(arr);
    }

}
